﻿<?php
    include_once("../db_config.php");
    include_once("./function.inventory.php");
    include_once("./function.vip.reg.php");

$time = date("Y-m-d h:i:s");

    # 数量查询
    function num($db_table,$table_name,$value){

        # 数据库查询
            if ($table_name == 'time'){
                $query = mysql_query("SELECT * FROM $db_table WHERE $table_name like '$value%' ");
              }
              else if ($table_name != NULL && $table_name != 'time'){
                $query = mysql_query("SELECT * FROM $db_table WHERE $table_name = '$value' ");
              }
            else{
                $query = mysql_query("SELECT * FROM $db_table ");
            }

        # 查询行数
        $num = mysql_num_rows($query);

        echo $num;
  }

    # 不能贴广告的地方查询
  function gwbn_disk_query(){
  	$query = mysql_query("SELECT * FROM gwbn_disk ORDER BY time");
  	if (!$query) {
  		echo "查询错误";
  	}
  	else{
  		while ($row = mysql_fetch_assoc($query)) {
  			if ($row["start"] == 1) {
  				echo '<li class="list-group-item">';
	  			echo $row["text"];
	  			echo '</li>';
  			}
  		}
  	}
  }

    # 供应商查询
    function gys_query(){

        # 数据库查询
        $query = mysql_query("SELECT * FROM gys ORDER BY id");

        if (!$query)
        {
            echo '<div class="alert alert-danger" role="alert">查询失败，请联系管理员!</div>';
        }
        else if ($num = mysql_num_rows($query) > 0)
            {
                 while($row=mysql_fetch_assoc($query))
                 {
                     echo '<tr>';
                     echo "<td>".$row['id']."</td>";
                     echo "<td>".$row['name']."</td>";
                     echo "<td>".$row['type']."</td>";
                     echo "<td>".$row['call_main']."</td>";
                     echo "<td>".$row['call_bk']."</td>";
                     echo "<td>".$row['addr']."</td>";
                     echo '</tr>';
                 }
             }
             else
             {
                echo'<div class="alert alert-danger" role="alert">没有找到供应商信息,请检查数据库!</div>';
             }
  }# 供应商查询

	# 员工查询
    function yg_query(){

        # 数据库查询
        $query = mysql_query("SELECT * FROM user ORDER BY level desc");

        if (!$query)
        {
            echo '<div class="alert alert-danger" role="alert">查询失败，请联系管理员!</div>';
        }
        else if ($num = mysql_num_rows($query) > 0)
            {
                 while($row=mysql_fetch_assoc($query))
                 {
                     echo '<tr>';
                     echo "<td>".$row['entry']."</td>";
                     echo "<td>".$row['name']."</td>";
                     echo "<td id='level_id_".$row['entry']."'>".$row['level']."</td>";
                     switch ($row['level']) {
                       case '0':
                         $name = "待审核";
                         break;
                        case '1':
                         $name = "向日葵电脑";
                         break;
                        case '2':
                         $name = "长城宽带";
                         break;
                        case '10':
                         $name = "管理员";
                         break;
                       
                       default:
                         $name = "什么鬼？";
                         break;
                     }
                     echo "<td id='cw_id_".$row['entry']."'>".$name."</td>";
                     echo "<td>".$row['call_b']."</td>";
                     echo "<td>".$row['username']."</td>";
                     echo '<td style="float: left;">
                        <a id="dislogin" class="btn btn-danger btn-xs" disabled="disabled">禁止登陆</a>';
                        if ($row['level'] == "0") {echo ' <button type="button" id="login_start_'.$row["entry"].'" class="btn btn-success btn-xs" onclick="login_start(this.value)" value='.$row['entry'].' >通过审核</button>';}
                     echo '</td>';
                     echo '</tr>';
                 }
             }
             else
             {
                echo'<div class="alert alert-danger" role="alert">没有找到员工信息,请检查数据库!</div>';
             }
  }# 员工查询


# 进度数量查询
function connent_num($table,$entry){
  $query_num = mysql_query("SELECT * FROM $table WHERE entry = $entry ");
                  if ($query_num > 0) {
                    while($log_row = mysql_fetch_assoc($query_num)){
                      for ($i=1; $i < 11; $i++) { 
                        if ($i <= 10) {
                            if ($log_row['content'.$i] == NULL) {
                            return $n = $i-1;
                            break;
                          }
                        }
                        else{
                          echo "ERR";
                        }
                      }
                    }
                  }
                  else{
                    echo "0";
                  }
}


    # JS处理
    if(isset($_POST["start"])){

        $start = addslashes($_POST["start"]); # 获取类别

        # 大循环
        switch ($start){

            # 登陆审核
            case "login_start":
              $entry = addslashes($_POST["id"]);
              $query = mysql_query("UPDATE user SET level='2' WHERE entry='$entry'");
              if (!$query) {
                echo "执行错误";
              }
              else {
                echo "审核成功！";
              }
            break;

            # ajax登陆 用户名检测
            case "login-name":
                num("user","name",addslashes($_POST["name"]));
            break;

            # ajax登陆 密码检测
            case "login-pass":

                $name = addslashes($_POST["name"]);
                $pass = addslashes($_POST["pass"]);
                $sha1_pass = sha1(strtoupper($name) . ":" . strtoupper($pass));

                # 用户名、密码检查
               $check = mysql_query("select * from user where name='$name'")  or die (mysql_error());

               $num = mysql_num_rows($check);

                if ($num > 0){
                  while($row = mysql_fetch_assoc($check)){
                      $uid    = $row["entry"];
                      $name = $row["name"];
                      $name1 = $row["username"];
                      $pass = $row["pass"];
                      $level = $row["level"];

                      if ($pass == $sha1_pass){
                        if ($level == 0) {
                          echo "8";
                          exit;
                        }
                        else{
                              $_SESSION['username'] = $name1;
                              $_SESSION['name'] = $name;
                              $_SESSION['userid'] = $uid;
                              $_SESSION['user_level'] = $level;
                              switch ($level){
                                  case "1":
                                      $_SESSION["level"] = "向日葵电脑";
                                      break;
                                  case "2":
                                      $_SESSION["level"] = "长城宽带";
                                      break;
                                  case "10":
                                      $_SESSION["level"] = "管理员";
                                      break;
                                  default:
                                     $name = "什么鬼？";
                                     break;
                              }
                              echo "1 ";
                              exit;
                            }
                          }
                      else {
                              echo "3";
                          }
                   }
                }
                else {
                  echo "0";
                }
            break;

            # 权限刷新
            case 'level_update':
                  $entry = addslashes($_POST["entry"]);
                  $query = mysql_query("SELECT * FROM user WHERE entry='$entry' ");
                  $num = mysql_num_rows($query);
                  if (!$query) {
                    echo "查询错误";
                  }
                  else if ($num > 0) {
                    while($row = mysql_fetch_assoc($query)){
                            echo $row["level"];
                        }
                    }
                    else{
                      echo "找不到数据";
                    }
              break;

              # 称谓刷新
            case 'cw_update':
                  $entry = addslashes($_POST["entry"]);
                  $query = mysql_query("SELECT * FROM user WHERE entry='$entry' ");
                  $num = mysql_num_rows($query);
                  if (!$query) {
                    echo "查询错误";
                  }
                  else if ($num > 0) {
                    while($row = mysql_fetch_assoc($query)){
                            switch ($row['level']) {
                             case '0':
                               $name = "待审核";
                               break;
                              case '1':
                               $name = "向日葵电脑";
                               break;
                              case '2':
                               $name = "长城宽带";
                               break;
                              case '3':
                               $name = "独孤求败";
                               break;
                               case '10':
                               $name = "管理员";
                               break;
                             
                             default:
                               $name = "什么鬼？";
                               break;
                           }
                           echo $name;
                        }
                    }
                    else{
                      echo "找不到数据";
                    }
              break;

            # 退出登陆
            case "logout":
              unset($_SESSION['userid']);
              unset($_SESSION['username']);
              session_destroy();
              echo "1";
            break;

            # 注册
            case "reg":
                $name = addslashes($_POST["name"]);
                $pass = addslashes($_POST["pass"]);
                $pass1 = addslashes($_POST["pass1"]);
                $name1 = addslashes($_POST["name1"]);
                $call = addslashes($_POST["call"]);
                $sha1_pass = sha1(strtoupper($name) . ":" . strtoupper($pass1));

                $reg = mysql_query("INSERT INTO `user`(`name`, `pass` , `call_b`, `username`)
                 VALUES ('$name','$sha1_pass','$call','$name1')");

                if (!$reg) {
                  echo "0";
                }
                else{
                  echo "1";
                }
            break;

            # 日程表刷新
            case "query-query":
                query_query("0");
            break;

            # 已完成任务刷新
            case "query-ok-query":
                query_query("1");
            break;

            # 取消任务刷新
            case "query-call-query":
                query_query("2");
            break;

            # 宽带数量刷新
            case "kh_kd_query":
                num("gwbn_azkh");
            break;

            # 任务数量刷新
            case "query-num0":
                num('query','start','0');
            break;

            # 任务数量刷新
            case "query-num1":
                num('query','start','1');
            break;

            # 任务数量刷新
            case "query-num2":
                num('query','start','2');
            break;

            # 白露流水账刷新
            case "item_bailu":
                item_query("bailu");
            break;

            # 白露今日消费刷新
            case "item-time-num-bailu":
                num('item_bailu','time',date('Y-m-d',time()));
            break;

            # 白露单据确认刷新
            case "item-ok-num-bailu":
                num('item_bailu','start','1');
            break;

            # 白露单据取消刷新
            case "item-call-num-bailu":
                num('item_bailu','start','2');
            break;

            # 白露未入账刷新
            case "item-no-num-bailu":
                num('item_bailu','start','0');
            break;

            # 宽带客户信息添加
            case "kd_kh_add":
                $account          = addslashes($_POST["kh_account"]);
                $cid          = addslashes($_POST["kh_cid"]);
                $name          = addslashes($_POST["kh_name"]);
                $call_main   = addslashes($_POST["kh_call"]);
                $time            = addslashes($_POST["kh_time"]);
                $otime            = addslashes($_POST["kh_otime"]);
                $speed          = addslashes($_POST["kh_speed"]);
                $onu_mac          = addslashes($_POST["kh_onu_mac"]);
                $onu_sn          = addslashes($_POST["kh_onu_sn"]);
                $onu_z          = addslashes($_POST["kh_onu_z"]);
                $poe_sn          = addslashes($_POST["kh_poe_sn"]);
                $poe_z          = addslashes($_POST["kh_poe_z"]);
                $domybox          = addslashes($_POST["kh_domybox"]);
                $domybox_mac          = addslashes($_POST["kh_domybox_mac"]);
                $price          = addslashes($_POST["kh_price"]);
                $addr            = addslashes($_POST["kh_addr"]);
                $addr2            = addslashes($_POST["kh_addr2"]);
                $mname            = addslashes($_POST["kh_mname"]);
                $zname          = addslashes($_POST["kh_zw"]);
                $source          = addslashes($_POST["kh_source"]);
                $remarks          = addslashes($_POST["kh_remarks"]);

                $call_query = mysql_query("SELECT call_main FROM gwbn_azkh WHERE call_main = $call_main");

                $num = mysql_num_rows($call_query);

                if ($num >= 1) {
                    	echo "客户已经存在";
                }
                else if ($call_main != NULL){

                    $user_info_add = mysql_query("INSERT INTO gwbn_azkh (
                      `account`,
                      `name`,
                      `cid`,
                      `call_main`,
                      `time`,
                      `otime`,
                      `addr2`,
                      `addr`,
                      `speed`,
                      `onu_mac`,
                      `onu_sn`,
                      `onu_z`,
                      `poe_sn`,
                      `poe_z`,
                      `domybox`,
                      `domybox_mac`,
                      `price`,
                      `mname`,
                      `zname`,
                      `source`,
                      `remarks`
                      )
                    VALUES (
                      '$account',
                      '$name',
                      '$cid',
                      '$call_main',
                      '$time',
                      '$otime',
                      '$addr2',
                      '$addr',
                      '$speed',
                      '$onu_mac',
                      '$onu_sn',
                      '$onu_z',
                      '$poe_sn',
                      '$poe_z',
                      '$domybox',
                      '$domybox_mac',
                      '$price',
                      '$mname',
                      '$zname',
                      '$source',
                      '$remarks'
                      )")or die (mysql_error());

                    if (!$user_info_add) {
                        echo "添加失败!";
                    }
                    else{
                        echo "添加成功";
                    }
                }
                else {
                    echo "手机没写";
                }
            break;

            # 宽带客户信息查询
            case "kd_search_kh":

                $type         = addslashes($_POST["kh_type"]); // 查询类型
                $search     = addslashes($_POST["kh_search"]); // 查询值

                if ($type == "all"){
                    $query = mysql_query("SELECT * FROM gwbn_azkh ORDER BY  time desc");
                    }
                else {
                    $query = mysql_query("SELECT * FROM gwbn_azkh WHERE $type like '%$search%' ORDER BY  time desc");
                    }

                $num = mysql_num_rows($query);

                if($query){
                    if ($num > 0){
                        while($row = mysql_fetch_assoc($query)){
                            echo '<tr>';
                            echo '<td>'.$row['name'].'</td>';
                            echo '<td>'.$row['call_main'].'</td>';
                            echo '<td>'.$row['time'].'</td>';
                            echo '<td>'.$row['otime'].'</td>';
                            echo '<td>'.$row['addr2'].'</td>';
                            echo '<td>'.$row['addr'].'</td>';
                            echo '<td>'.$row['speed'].'</td>';
                            echo '<td>'.$row['price'].'</td>';
                            echo '<td>'.$row['mname'].'</td>';
                            echo '<td>'.$row['zname'].'</td>';
                            echo '<td>'.$row['source'].'</td>';
                            echo '<td>'.$row['remarks'].'</td>';
                            echo '</tr>';
                        }
                    }
                    else {
                        echo "0";
                    }
                }
                break; #宽带客户信息结束

                # 供应商添加
                case "gys_add":
                    $type       = addslashes($_POST["type"]);
                    $name       = addslashes($_POST["user"]);
                    $call_main  = addslashes($_POST["call_main"]);
                    $call_bk    = addslashes($_POST["call_bk"]);
                    $addr       = addslashes($_POST["addr"]);

                    if ($call_main != NULL){

                        $gys_add = mysql_query("INSERT INTO gys (`type`,`name`,`call_main`,`call_bk`,`addr`)

                        VALUES ('$type','$name','$call_main','$call_bk','$addr')")or die (mysql_error());

                            if (!$gys_add) {
                                echo "添加失败!";
                            }
                            else {
                                echo "添加成功!";
                            }
                        }
                        else {
                            echo "电话必须要填写至少1个!";
                        }
                break;

                # 添加任务
                case "query_add":
                    $time      = addslashes($_POST["query_time"]);
                    $call       = addslashes($_POST["query_call"]);
                    $content    = addslashes($_POST["query_content"]);
                    $addr       = addslashes($_POST["query_addr"]);
                    $name      = addslashes($_POST["query_name"]);

                    if ($call != NULL){

                        $query_add = mysql_query("INSERT INTO xrk_query (`time`,`call_main`,`content`,`addr`,`name`)

                        VALUES ('$time','$call','$content','$addr','$name')");

                        if (!$query_add) {
                            echo "添加失败!";
                        }
                         else{
                            echo "添加成功！";
                        }
                    }
                    else {

                        echo "电话必须要填写!";
                    }
                break;

                # 添加任务跟踪
                case "query_add_new":
                if(!isset($_SESSION["userid"])){
		    	header ( 'Location: /' );
      			exit;
		    	}
                    $start            = addslashes($_POST["entry"]);
                    $num     = addslashes($_POST["num"]);
                    $text                = addslashes($_POST["text"]);
                    $name          = addslashes($_POST["username"]);
                    $time       = date('Y-m-d H:i:s',time());

                    $query = mysql_query("update `xrk_query` set
                      `content$num`='$text' ,
                      `name$num` = '$name' ,
                      `time$num` = '$time'
                      where `entry`=$start; ");

                    if(!$query) {
                        echo "更新失败";
                    }
                    else {
                        echo "更新成功";
                    }
                break;

                # 任务确认完成
                case "query_ok":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE xrk_query SET start='1' WHERE entry='$start'");

                    if(!$query) {
                        echo "确认失败！";
                    }
                    else{
                        echo "成功确认！";
                    }
                break;

                # 任务取消
                case "query_call":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE xrk_query SET start = '2' WHERE entry = '$start'");

                    if(!$query) {
                       echo "取消失败";
                    }
                    else {
                       echo "取消成功";
                    }
                break;

                ######################
                ############ 长城宽带
                ######################

                # 添加不能贴广告的地方
                case "gwbn_disk_add":
                	$text = addslashes($_POST["text"]);
                	$name = $_SESSION["username"];
                	$time = date('Y-m-d H:i:s',time());
                	if ($text != NULL) {
                		$query = mysql_query("INSERT INTO gwbn_disk (`time`,`text`,`name`) VALUES ('$time','$text','$name')");
                		if (!$query) {
                			echo "0";
                		}
                		else{
                			echo "1";
                		}
                	}
                	else{
                		echo "8";
                	}
                break;

                # 添加意向客户
                case "gwbn_yxkh_add":
                    $time      = addslashes($_POST["gwbn_yxkh_time"]);
                    $call       = addslashes($_POST["gwbn_yxkh_call"]);
                    $khname       = addslashes($_POST["gwbn_yxkh_khname"]);
                    $content    = addslashes($_POST["gwbn_yxkh_content"]);
                    $addr       = addslashes($_POST["gwbn_yxkh_addr"]);
                    $addr2       = addslashes($_POST["gwbn_yxkh_addr2"]);
                    $name      = addslashes($_POST["gwbn_yxkh_name"]);
                    $otime    = addslashes($_POST["gwbn_yxkh_otime"]);
                    $kd     = addslashes($_POST["gwbn_yxkh_kd"]);

                    if ($call != NULL){

                    	$call_query = mysql_query("SELECT call_main FROM gwbn_yxkh WHERE call_main = $call");

                    	$num = mysql_num_rows($call_query);

                    	if ($num >= 1) {
                    		echo "客户已经存在";
                    	}
                    	else{
                    		$query_add = mysql_query("INSERT INTO gwbn_yxkh (`time`,`call_main`,`khname`,`text`,`addr`,`addr2`,`name`,`tname`,`otime`)

	                        	VALUES ('$time','$call','$khname','$content','$addr','$addr2','$name','$kd','$otime')");

	                        	if (!$query_add) {
	                            	echo "添加失败!";
	                       	 }
	                         	else{
	                            	echo "添加成功！";
	                        	}
                    	}
                    }
                    else {
                        echo "电话必须要填写!";
                    }
                break;

                # 不能贴广告的地方刷新
              case 'gwbn-disk-query':
              	gwbn_disk_query();
              break;
                # 未完成意向客户刷新
              case "gwbn-yxkh-query":
                  gwbn_yxkh("0");
              break;

              # 已完成意向客户刷新
              case "gwbn-yxkh-ok-query":
                  gwbn_yxkh("1");
              break;

              # 取消意向客户刷新
              case "gwbn-yxkh-call-query":
                  gwbn_yxkh("2");
              break;

              # 意向客户未完成数量刷新
              case "gwbn-yxkh-num0":
                  num('gwbn_yxkh','start','0');
              break;

              # 意向客户完成数量刷新
              case "gwbn-yxkh-num1":
                  num('gwbn_yxkh','start','1');
              break;

              # 意向客户取消数量刷新
              case "gwbn-yxkh-num2":
                  num('gwbn_yxkh','start','2');
              break;

              # 意向客户确认完成
                case "gwbn_yxkh_ok":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE gwbn_yxkh SET start='1' WHERE entry='$start'");

                    if(!$query) {
                        echo "确认失败！";
                    }
                    else{
                        echo "确认成功！";
                    }
                break;

                # 添加意向客户回访
                case "gwbn_yxkh_add_new":
                if(!isset($_SESSION["userid"])){
          		header ( 'Location: /' );
      			exit;
      		    }
                    $start            = addslashes($_POST["entry"]);
                    $gwbn_yxkh_num   = addslashes($_POST["gwbn_yxkh_num"]);
                    $gwbn_yxkh_name  = addslashes($_POST["gwbn_yxkh_name"]);
                    $gwbn_yxkh_text  = addslashes($_POST["gwbn_yxkh_text"]);
                    $time       = date('Y-m-d H:i:s',time());

                    $query = mysql_query("update `gwbn_yxkh` set 
                      `content$gwbn_yxkh_num` = '$gwbn_yxkh_text',
                      `name$gwbn_yxkh_num` = '$gwbn_yxkh_name',
                      `time$gwbn_yxkh_num` = '$time'
                      where `entry` = $start; 
                      ");

                    if(!$query) {
                        echo "更新失败";
                    }
                    else {
                        echo "更新成功";
                    }
                break;

                # 意向客户取消
                case "gwbn_yxkh_call":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE gwbn_yxkh SET start = '2' WHERE entry = '$start'");

                    if(!$query) {
                       echo "取消失败";
                    }
                    else {
                       echo "取消成功";
                    }
                break;

                //-----------------------/
                # 日程表
                # 添加意向客户
                case "gwbn_query_add":
                    $time      = addslashes($_POST["gwbn_query_time"]);
                    $call       = addslashes($_POST["gwbn_query_call"]);
                    $content    = addslashes($_POST["gwbn_query_content"]);
                    $addr       = addslashes($_POST["gwbn_query_addr"]);
                    $name      = addslashes($_POST["gwbn_query_name"]);

                    if ($call != NULL){

                        $query_add = mysql_query("INSERT INTO gwbn_query (`time`,`call_main`,`text`,`addr`,`name`)

                        VALUES ('$time','$call','$content','$addr','$name')");

                        if (!$query_add) {
                            echo "添加失败!";
                        }
                         else{
                            echo "添加成功！";
                        }
                    }
                    else {

                        echo "电话必须要填写!";
                    }
                break;

                # 未完成意向客户刷新
              case "gwbn-query-query":
                  gwbn_query("0");
              break;

              # 已完成意向客户刷新
              case "gwbn-query-ok-query":
                  gwbn_query("1");
              break;

              # 取消意向客户刷新
              case "gwbn-query-call-query":
                  gwbn_query("2");
              break;

              # 意向客户未完成数量刷新
              case "gwbn-query-num0":
                  num('gwbn_query','start','0');
              break;

              # 意向客户完成数量刷新
              case "gwbn-query-num1":
                  num('gwbn_query','start','1');
              break;

              # 意向客户取消数量刷新
              case "gwbn-query-num2":
                  num('gwbn_query','start','2');
              break;

              # 意向客户确认完成
                case "gwbn_query_ok":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE gwbn_query SET start='1' WHERE entry='$start'");

                    if(!$query) {
                        echo "确认失败！";
                    }
                    else{
                        echo "确认成功！";
                    }
                break;

                # 添加意向客户回访
                case "gwbn_query_add_new":
                if(!isset($_SESSION["userid"])){
          		header ( 'Location: /' );
      			exit;
          	}
                    $start            = addslashes($_POST["entry"]);
                    $gwbn_query_num   = addslashes($_POST["gwbn_query_num"]);
                    $gwbn_query_name  = addslashes($_POST["gwbn_query_name"]);
                    $gwbn_query_text  = addslashes($_POST["gwbn_query_text"]);
                    $time       = date('Y-m-d H:i:s',time());

                    $query = mysql_query("update `gwbn_query` set 
                      `content$gwbn_query_num` = '$gwbn_query_text',
                      `name$gwbn_query_num` = '$gwbn_query_name',
                      `time$gwbn_query_num` = '$time'
                      where `entry` = $start; 
                      ");

                    if(!$query) {
                        echo "更新失败";
                    }
                    else {
                        echo "更新成功";
                    }
                break;

                # 意向客户取消
                case "gwbn_query_call":
                    $start = addslashes($_POST["entry"]);

                    $query = mysql_query("UPDATE gwbn_query SET start = '2' WHERE entry = '$start'");

                    if(!$query) {
                       echo "取消失败";
                    }
                    else {
                       echo "取消成功";
                    }
                break;
        }# 大循环结束

    }

########### 长城宽带

# 意向客户查询
  function gwbn_yxkh($value){
  	if(!isset($_SESSION["userid"])){
    		header ( 'Location: /' );
      		exit;
    	}

      	$un = $_SESSION['username'];

      	if ($_SESSION["userid"] == 7 || $_SESSION["userid"] == 1 || $_SESSION["userid"] == 41){

      		$query = mysql_query("SELECT * FROM gwbn_yxkh WHERE start=$value ORDER BY  time desc")or die(mysql_error());

      	}
      	else{

      		$query = mysql_query("SELECT * FROM gwbn_yxkh WHERE name='$un'  AND start=$value ORDER BY  time desc")or die(mysql_error());

      	}

        $num = mysql_num_rows($query);

        if(!$query){
             echo "执行错误";
            }
            else if($num > 0){
                while($log_row = mysql_fetch_assoc($query)){
                  $a = $log_row['entry'];
                  $nnn = $log_row['text'];
                  $str2 = mb_substr($nnn, 0,15,'utf-8'); // 截断文本
                  $num = strlen($nnn);
                  if($value == 0){
                      echo '<tr>';
                      echo '<td style="word-break:break-all;width: 150px;">'.$log_row['time'].'</td>';
                      echo '<td style="word-break:break-all;width: 110px;" id='.$log_row['call_main'].'>'.$log_row['call_main'].'</td>';
                      echo '<td>'.$log_row["khname"].'</td>';
                      if ($num > 80) {
                        echo '<td style="word-break:break-all;width: 300px;color:green;">'.$str2.'.....<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#gwbn-yxkh-'.$log_row['entry'].'-connent">查看更多</button></td>
                                    <!-- Modal -->
                                    <div class="modal fade bs-example-modal-sm" id="gwbn-yxkh-'.$log_row['entry'].'-connent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="myModalLabel">更多</h4>
                                          </div>
                                          <div class="modal-body">
                                            '.$log_row['text'].'
                                          </div>
                                          <div class="modal-footer">
                                            <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                        ';
                      }
                      else {
                        echo '<td style="word-break:break-all;width: 300px;">'.$log_row['text'].'</td>';
                      }
                      if ($log_row['content1'] == NULL){
                        echo '<td style="word-break:break-all;width: 60px;">NULL</td>';
                      }
                      else {
                      echo '<td style="word-break:break-all;width: 60px;">
                      <button type="submit" class="btn btn-primary btn-xs yxkh_new" data-toggle="modal" data-target="#gwbn-yxkh-'.$log_row['entry'].'-content">查看回访 <span class="badge">'; echo connent_num('gwbn_yxkh',$a); echo '</span></button>

                      <div class="modal fade bs-example-modal-lg" id="gwbn-yxkh-'.$log_row['entry'].'-content" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                          <div class="modal-content">
                             <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                   <h4 class="modal-title" id="myModalLabel">回访跟踪</h4>
                             </div>
                             <div class="modal-body">
                                   <table class="table table-responsive table-bordered table-condensed table-hover" style="font-size: 0.7em;">
								    <thead style="background-color: rgb(105, 200, 175); font-size: 1em; ">
								    	<th style=" width: 160px; text-align: center;">时间</th>
								    	<th style=" width: 50px; text-align: center;">次数</th>
								    	<th style=" width: 50px; text-align: center;">回访人</th>
								    	<th style="text-align: center;">回访结果</th>
								    </thead>
								    <tbody>';
								    	for ($i=1; $i < 11; $i++) { 
								    		echo "<tr>";
								    		echo '<th style=" width: 160px; text-align: center;">'.$log_row['time'.$i].'</th>';
								    		echo '<td style=" width: 50px; text-align: center;">'.$i.'</td>';
								    		echo '<td style=" width: 50px; text-align: center;">'.$log_row['name'.$i].'</td>';
								    		echo '<td>'.$log_row['content'.$i].'</td>';
								    		echo "</tr>";
								    	}
								    echo '
								    </tbody>
								    </table>
                             </div>
                            <div class="modal-footer">
                             <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                           </div>
                          </div>
                        </div>
                      </div>
                      </td>';
                      }
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['addr2'].'</td>';
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['addr'].'</td>';
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['tname'].'</td>';
                      echo '<td style="word-break:break-all;width: 150px;">'.$log_row['otime'].'</td>';
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['name'].'</td>';
                      echo '<td style="word-break:break-all;width: 240px;">
                      <button type="submit" class="btn btn-success btn-xs yxkh_ok" onclick="gwbn_yxkh_ok(this.value)"  value='.$log_row['entry'].'>确认</button>
                      <button type="submit" class="btn btn-info btn-xs yxkh_new" data-toggle="modal" data-target="#gwbn-yxkh-hf-'.$log_row['entry'].'">回访</button>

                      <div class="modal fade" id="gwbn-yxkh-hf-'.$log_row['entry'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                          <div class="modal-content">
                             <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                   <h4 class="modal-title" id="myModalLabel">回访跟踪</h4>
                             </div>
                             <div class="modal-body">
                                   <form class="form" role="form">
                                      <div class="form-group">
                                        <label for="exampleInputTexi" style="font-size: 3em;">第<b style="color:green;">';  echo connent_num('gwbn_yxkh',$a) + 1; echo '</b>次回访</label>
                                            <input type="hidden" class="form-control" id="gwbn_yxkh_hf_'.$log_row['entry'].'" value="'; echo connent_num('gwbn_yxkh',$a) + 1; echo'">
                                      </div>
                                      <div class="form-group">
                                         <label for="exampleInputTexi">回访结果</label>
                                            <textarea class="form-control" rows="10" id="gwbn-yxkh-'.$log_row['entry'].'-text"></textarea>
                                      </div>
                                      <div class="form-group">
                                         <label for="exampleInputTexi">回访人</label>
                                            <input type="Texi" class="form-control yxkh-new-pri" id="gwbn-yxkh-'.$log_row['entry'].'-name"  disabled="disabled" value="'.$_SESSION['username'].'">
                                      </div>
                                   </form>
                             </div>
                            <div class="modal-footer">
                             <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                             <button type="button" class="btn btn-primary yxkh-connent-add" onclick="gwbn_yxkh_add_new(this.value)"  value='.$log_row['entry'].'>确定添加</button>
                           </div>
                          </div>
                        </div>
                      </div>

                      <button type="submit" class="btn btn-danger btn-xs yxkh_call" onclick="gwbn_yxkh_call(this.value)" value='.$log_row['entry'].'>取消</button>
                      </td>';
                      echo '</tr>';
                      }
                  if($value == 1){
                      echo '<tr>';
                      echo '<td>'.$log_row['time'].'</td>';
                      echo '<td>'.$log_row['call_main'].'</td>';
                      echo '<td>'.$log_row['content'].'</td>';
                      if ($log_row['content-new'] == NULL){
                         echo "<td>无</td>";
                      }
                      else {
                         echo '<td style="color:red">'.$log_row['content-new'].'</td>';
                      }
                      echo '<td>'.$log_row['addr'].'</td>';
                      echo '<td>'.$log_row['name'].'</td>';
                      echo '<td>'.$log_row['newname'].'</td>';
                      echo '<td>'.$log_row['pri'].'</td>';
                      echo '<td>已完成任务</td>';
                      echo '</tr>';
                      }
                  if($value == 2){
                      echo '<tr>';
                      echo '<td>'.$log_row['time'].'</td>';
                      echo '<td>'.$log_row['call_main'].'</td>';
                      echo '<td>'.$log_row['content'].'</td>';
                      if ($log_row['content-new'] == NULL){
                         echo "<td>无</td>";
                      }
                      else {
                         echo '<td style="color:red">'.$log_row['content-new'].'</td>';
                      }
                      echo '<td>'.$log_row['addr'].'</td>';
                      echo '<td>'.$log_row['name'].'</td>';
                      echo '<td>'.$log_row['newname'].'</td>';
                      echo '<td>'.$log_row['pri'].'</td>';
                      echo '<td>已取消任务</td>';
                      echo '</tr>';
                     }
                }
            }
            else{
                    echo "没有数据";
                }
      }

      # 宽带日程表查询
  function gwbn_query($value){
    if(!isset($_SESSION["userid"])){
      	header ( 'Location: /' );
      	exit;
      }
        $query = mysql_query("SELECT * FROM gwbn_query WHERE start=$value ORDER BY  time desc");
        $num = mysql_num_rows($query);

        if(!$query){
             echo "执行错误";
            }
            else if($num > 0){
                while($log_row = mysql_fetch_assoc($query)){
                  $a = $log_row['entry'];
                  $nnn = $log_row['text'];
                  $str2 = mb_substr($nnn, 0,15,'utf-8'); // 截断文本
                  $num = strlen($nnn);
                  if($value == 0){
                      echo '<tr>';
                      echo '<td style="word-break:break-all;width: 150px;">'.$log_row['time'].'</td>';
                      echo '<td style="word-break:break-all;width: 110px;">'.$log_row['call_main'].'</td>';
                      if ($num > 80) {
                        echo '<td style="word-break:break-all;width: 300px;color:green;">'.$str2.'.....<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#gwbn-query-'.$log_row['entry'].'-connent">查看更多</button></td>
                                    <!-- Modal -->
                                    <div class="modal fade bs-example-modal-sm" id="gwbn-query-'.$log_row['entry'].'-connent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="myModalLabel">更多</h4>
                                          </div>
                                          <div class="modal-body">
                                            '.$log_row['text'].'
                                          </div>
                                          <div class="modal-footer">
                                            <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                        ';
                      }
                      else {
                        echo '<td style="word-break:break-all;width: 300px;">'.$log_row['text'].'</td>';
                      }
                      if ($log_row['content1'] == NULL){
                        echo '<td style="word-break:break-all;width: 60px;">NULL</td>';
                      }
                      else {
                      echo '<td style="word-break:break-all;width: 60px;">
                      <button type="submit" class="btn btn-primary btn-xs query_new" data-toggle="modal" data-target="#gwbn-query-'.$log_row['entry'].'-content">查看进度<span class="badge">'; echo connent_num('gwbn_query',$a); echo'</span></button>

                      <div class="modal fade bs-example-modal-lg" id="gwbn-query-'.$log_row['entry'].'-content" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                          <div class="modal-content">
                             <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                   <h4 class="modal-title" id="myModalLabel">进度跟踪</h4>
                             </div>
                             <div class="modal-body">
                                   <table class="table table-responsive table-bordered table-condensed table-hover" style="font-size: 0.7em;">
                    <thead style="background-color: rgb(105, 200, 175); font-size: 1em; ">
                      <th style=" width: 160px; text-align: center;">时间</th>
                      <th style=" width: 50px; text-align: center;">次数</th>
                      <th style=" width: 50px; text-align: center;">执行人</th>
                      <th style="text-align: center;">执行结果</th>
                    </thead>
                    <tbody>';
                      for ($i=1; $i < 11; $i++) { 
                        echo "<tr>";
                        echo '<th style=" width: 160px; text-align: center;">'.$log_row['time'.$i].'</th>';
                        echo '<td style=" width: 50px; text-align: center;">'.$i.'</td>';
                        echo '<td style=" width: 50px; text-align: center;">'.$log_row['name'.$i].'</td>';
                        echo '<td>'.$log_row['content'.$i].'</td>';
                        echo "</tr>";
                      }
                    echo '
                    </tbody>
                    </table>
                             </div>
                            <div class="modal-footer">
                             <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                           </div>
                          </div>
                        </div>
                      </div>
                      </td>';
                      }
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['addr'].'</td>';
                      echo '<td style="word-break:break-all;width: 100px;">'.$log_row['name'].'</td>';
                      echo '<td style="word-break:break-all;width: 240px;">
                      <button type="submit" class="btn btn-success btn-xs query_ok" onclick="gwbn_query_ok(this.value)"  value='.$log_row['entry'].'>确认</button>
                      <button type="submit" class="btn btn-info btn-xs query_new" data-toggle="modal" data-target="#gwbn-query-hf-'.$log_row['entry'].'">更新进度</button>

                      <div class="modal fade" id="gwbn-query-hf-'.$log_row['entry'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                          <div class="modal-content">
                             <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                   <h4 class="modal-title" id="myModalLabel">进度跟踪</h4>
                             </div>
                             <div class="modal-body">
                                   <form class="form" role="form">
                                      <div class="form-group">
                                        <label for="exampleInputTexi" style="font-size: 3em;">第<b style="color:green;">';  echo connent_num('gwbn_query',$a) + 1; echo '</b>次回访</label>
                                            <input type="hidden" class="form-control" id="gwbn_query_hf_'.$log_row['entry'].'" value="'; echo connent_num('gwbn_query',$a) + 1; echo'">
                                      </div>
                                      <div class="form-group">
                                         <label for="exampleInputTexi">执行结果</label>
                                            <textarea class="form-control" rows="10" id="gwbn-query-'.$log_row['entry'].'-text"></textarea>
                                      </div>
                                      <div class="form-group">
                                         <label for="exampleInputTexi">执行人</label>
                                            <input type="Texi" class="form-control query-new-pri" id="gwbn-query-'.$log_row['entry'].'-name"  disabled="disabled" value="'.$_SESSION['username'].'">
                                      </div>
                                   </form>
                             </div>
                            <div class="modal-footer">
                             <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                             <button type="button" class="btn btn-primary query-connent-add" onclick="gwbn_query_add_new(this.value)"  value='.$log_row['entry'].'>确定添加</button>
                           </div>
                          </div>
                        </div>
                      </div>

                      <button type="submit" class="btn btn-danger btn-xs query_call" onclick="gwbn_query_call(this.value)" value='.$log_row['entry'].'>取消</button>
                      </td>';
                      echo '</tr>';
                      }
                  if($value == 1){
                      echo '<tr>';
                      echo '<td>'.$log_row['time'].'</td>';
                      echo '<td>'.$log_row['call_main'].'</td>';
                      echo '<td>'.$log_row['content'].'</td>';
                      if ($log_row['content-new'] == NULL){
                         echo "<td>无</td>";
                      }
                      else {
                         echo '<td style="color:red">'.$log_row['content-new'].'</td>';
                      }
                      echo '<td>'.$log_row['addr'].'</td>';
                      echo '<td>'.$log_row['name'].'</td>';
                      echo '<td>'.$log_row['newname'].'</td>';
                      echo '<td>'.$log_row['pri'].'</td>';
                      echo '<td>已完成任务</td>';
                      echo '</tr>';
                      }
                  if($value == 2){
                      echo '<tr>';
                      echo '<td>'.$log_row['time'].'</td>';
                      echo '<td>'.$log_row['call_main'].'</td>';
                      echo '<td>'.$log_row['content'].'</td>';
                      if ($log_row['content-new'] == NULL){
                         echo "<td>无</td>";
                      }
                      else {
                         echo '<td style="color:red">'.$log_row['content-new'].'</td>';
                      }
                      echo '<td>'.$log_row['addr'].'</td>';
                      echo '<td>'.$log_row['name'].'</td>';
                      echo '<td>'.$log_row['newname'].'</td>';
                      echo '<td>'.$log_row['pri'].'</td>';
                      echo '<td>已取消任务</td>';
                      echo '</tr>';
                     }
                }
            }
            else{
                    echo "没有数据";
                }
      }

      # 意向客户检查，防止已安装客户未确认
      function gwbn_yxkh_ck(){

          $query = mysql_query("SELECT  `gwbn_yxkh`.`call_main` ,  `gwbn_azkh`.`call_main` ,  `gwbn_yxkh`.`start` 
                                                    FROM  `gwbn_yxkh` ,  `gwbn_azkh` 
                                                    WHERE (
                                                    `gwbn_yxkh`.`call_main` =  `gwbn_azkh`.`call_main`
                                                    )
                                                    AND (
                                                    `gwbn_yxkh`.`start` = '0'
                                                    )");

          if (!$query) {
            echo "查询错误";
          }
          else{
            while($log_row = mysql_fetch_assoc($query)){
              if ($log_row['call_main'] == "") {
                echo "当前没有冲突";
              }
              else{
                echo "<a style='color:green;' href='#".$log_row['call_main']."'>".$log_row['call_main']." </a>、";
              }
            }
          }
      }

########### 额外组件

function isMobile() {
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
        return true;
    }
    // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset($_SERVER['HTTP_VIA'])) {
        // 找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true: false;
    }
    // 脑残法，判断手机发送的客户端标志,兼容性有待提高
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(".implode('|', $clientkeywords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    // 协议法，因为有可能不准确，放到最后判断
    if (isset($_SERVER['HTTP_ACCEPT'])) {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}
?>
